package com.wswy.wzcx.ui.dialog

import android.Manifest
import android.content.Context
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatDialog
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.view.View
import android.view.Window
import com.wswy.wzcx.R
import kotlinx.android.synthetic.main.dialog_permission_hint.*

class PermissionHintDialog(context: Context,private val shouldReq:List<String>, private val requestPermission: (()->Unit?) ) : AppCompatDialog(context) {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        window?.requestFeature(Window.FEATURE_NO_TITLE)

        //window.decorView.setPadding(0,0,0,0)

        setCancelable(false)
        setCanceledOnTouchOutside(false)

        setContentView(R.layout.dialog_permission_hint)


        if(!shouldReq.contains(Manifest.permission.WRITE_EXTERNAL_STORAGE)){
            ll_sd_store.visibility = View.GONE
        }

        if(!shouldReq.contains(Manifest.permission.READ_PHONE_STATE)){
            ll_device_info.visibility = View.GONE
        }

        if(!shouldReq.contains(Manifest.permission.ACCESS_FINE_LOCATION)){
            ll_device_address.visibility = View.GONE

        }else{
            tv_address_option.append(SpannableString("(可选)").apply {
                setSpan(ForegroundColorSpan(ContextCompat.getColor(context,R.color.textColorPrimary_40)),0,length,SpannableString.SPAN_INCLUSIVE_EXCLUSIVE)
            })

        }


        btn_next.setOnClickListener {
            dismiss()
            requestPermission.invoke()
        }

    }

}